<?php

use App\Admin\Controllers as C;
use Illuminate\Support\Facades\Route;

if (config('app.env') == 'local') {
    Route::any('/test', [C\TestSomethingController::class, 'export']);
}

Route::get('/admin/{path?}', [C\RedirectController::class, 'index'])->where('path', '.*')->name('redirect.index');
Route::get('/admin-dev/{path?}', [C\RedirectController::class, 'indexDev'])->where('path', '.*')->name('redirect.index-dev');

Route::prefix('admin-api')
    ->middleware('admin')
    ->as('admin.')
    ->group(function () {
        Route::post('auth/login', [C\Auth\LoginController::class, 'login'])->name('login');

        // API文档
        Route::get('api-documents', [C\ApiDocumentController::class, 'index']);
        Route::get('api-documents/format', [C\ApiDocumentController::class, 'format']);
        Route::post('api-documents', [C\ApiDocumentController::class, 'store']);
        Route::delete('api-documents/truncate', [C\ApiDocumentController::class, 'truncate']);

        $middleware = [];
        if (config()->get('app.env')=='production') {
            $middleware = [
                'admin.log',
                'admin.auth',
                'admin.permission'
            ];
        }
        Route::middleware($middleware)->group(function () {
            Route::post('auth/logout', [C\Auth\LoginController::class, 'logout'])->name('logout');

            Route::get('user', [C\AdminUserController::class, 'user'])->name('user');
            Route::get('user/edit', [C\AdminUserController::class, 'editUser'])->name('user.edit');
            Route::put('user', [C\AdminUserController::class, 'updateUser'])->name('user.update');

            // 管理员
            Route::resource('admin-users', C\AdminUserController::class);

            // 操作日志
            Route::resource('admin-operation-logs', C\AdminOperationLogController::class);

            // 管理员权限
            Route::resource('admin-permissions', C\AdminPermissionController::class);

             // 管理员角色
            Route::resource('admin-roles', C\AdminRoleController::class);

            Route::resource('config-categories', C\ConfigCategoryController::class)->except(['show', 'create']);

            Route::post('vue-routers/by-import', [C\VueRouterController::class, 'importVueRouters'])->name('vue-routers.by-import');
            Route::put('vue-routers', [C\VueRouterController::class, 'batchUpdate'])->name('vue-routers.batch.update');
            Route::resource('vue-routers', C\VueRouterController::class)->except(['show']);

            Route::post('vue-admin-user-routers/by-import', [C\VueAdminUserRouterController::class, 'importVueAdminUserRouters'])->name('vue-admin-user-routers.by-import');
            Route::put('vue-admin-user-routers', [C\VueAdminUserRouterController::class, 'batchUpdate'])->name('vue-routers.batch.update');
            Route::resource('vue-admin-user-routers', C\VueAdminUserRouterController::class)->except(['show']);

            Route::post('system-models/by-import', [C\SystemModelController::class, 'importSystemModels'])->name('system-models.by-import');
            Route::put('system-models', [C\SystemModelController::class, 'batchUpdate'])->name('system-models.batch.update');
            Route::resource('system-models', C\SystemModelController::class)->except(['show']);
            // 获取模型字段
            Route::get('system-models/{id}', [C\SystemModelController::class, 'field']);
            // 更新模型字段
            Route::put('system-models/{id}/updateField', [C\SystemModelController::class, 'updateField']);

            // 清除并缓存配置
            Route::post('configs/cache', [C\ConfigController::class, 'cache'])->name('configs.cache');
            // 获取后台路由配置，会做权限筛选，用来生成前端菜单和路由
            Route::get('configs/vue-routers', [C\ConfigController::class, 'vueRouters'])->name('configs.vue-routers');
            // 配置的增删改查
            Route::resource('configs', C\ConfigController::class)->except(['show']);
            // 配置详情
            Route::get('configs/{id}', [C\ConfigController::class, 'show'])
                // 只接受数字作为参数id
                ->where('id', '[0-9]+');
            // 通过分类名获取配置列表，用在用户在后台配置时，生成配置表单
            Route::get('configs/{category_slug}', [C\ConfigController::class, 'getByCategorySlug'])
                // 只接受字母、数字、短划线和下划线作为参数category_slug
                ->where('category_slug', '[a-zA-Z0-9\-_]+'); 
            // 通过分类名获取配置的键值对，用在前端获取配置键值对，比如系统首次请求，获取后台名称，是否需要验证码等配置
            Route::get('configs/{category_slug}/values', [C\ConfigController::class, 'getValuesByCategorySlug'])
                ->name('configs.values.by-category-slug');
            // 用户在后台更新配置
            Route::put('configs/{category_slug}/values', [C\ConfigController::class, 'updateValues'])
                ->name('configs.update-values');
            // 获取选项配置
            Route::get('getSelectConfigs', [C\ConfigController::class, 'getSelectConfigs']);

            Route::resource('system-media-categories', C\SystemMediaCategoryController::class)->except(['show', 'create']);
            // 在指定分类下，上传文件
            Route::post(
                'system-media-categories/{system_media_category}/system-media',
                [C\SystemMediaCategoryController::class, 'storeSystemMedia']
            )->name('system-media-categories.system-media.store');
            // 获取指定分类下的所有文件
            Route::get(
                'system-media-categories/{system_media_category}/system-media',
                [C\SystemMediaCategoryController::class, 'systemMediaIndex']
            )->name('system-media-categories.system-media.index');

            Route::resource('system-media', C\SystemMediaController::class)
                // system-media 自动转成单数后 变为了 system-sedium
                // 所以手动指定
                ->parameters(['system-media' => 'system_media'])
                ->except(['store', 'show', 'create']);
            Route::put('system-media', [C\SystemMediaController::class, 'batchUpdate'])->name('system-media.batch.update');
            Route::delete('system-media', [C\SystemMediaController::class, 'batchDestroy'])->name('system-media.batch.destroy');
            Route::post('system-media/download', [C\SystemMediaController::class, 'download']);
            // 软删除恢复
            Route::put('restore/{route_id}/{id}', [C\SystemModelController::class, 'restore']);
            // 彻底删除
            Route::delete('forceDelete/{route_id}/{id}', [C\SystemModelController::class, 'forceDelete']);
            // 批量软删除
            Route::delete('deleteBatch/{route_id}', [C\SystemModelController::class, 'deleteBatch']);
            // 批量彻底删除
            Route::delete('forceDeleteBatch/{route_id}', [C\SystemModelController::class, 'forceDeleteBatch']);
            // 软删除批量恢复
            Route::put('restoreBatch/{route_id}', [C\SystemModelController::class, 'restoreBatch']);
            // 列表页字段
            Route::get('listField/{id}', [C\Controller::class, 'listField']);
            // 搜索栏字段
            Route::get('searchField/{id}', [C\Controller::class, 'searchField']);
            // 表单页字段
            Route::get('formField/{id}', [C\Controller::class, 'formField']);
            // 详情页字段
            Route::get('detailField/{id}', [C\Controller::class, 'detailField']);
            // 提示字段
            Route::get('hintField', [C\Controller::class, 'hintField']);
            // 获取选项设置
            Route::post('getParseOptions', [C\Controller::class, 'getParseOptions']);
            // 获取内部标题
            Route::post('getInnerTitle', [C\ConfigController::class, 'getInnerTitle']);
// 歌单导出
Route::post('worship-collections/export/{id}', [C\WorshipCollectionController::class, 'export']);
// 主日PPT导出
Route::post('worship-ppts/export/{id}', [C\WorshipPptController::class, 'export']);
Route::resource('worship-bible-chapters', C\WorshipBibleChapterController::class);
Route::resource('worship-bible-volumes', C\WorshipBibleVolumeController::class);
Route::resource('worship-hymns', C\WorshipHymnController::class);
Route::resource('worship-collections', C\WorshipCollectionController::class);
Route::resource('worship-hymns', C\WorshipHymnController::class);
Route::resource('worship-ppts', C\WorshipPptController::class);
Route::resource('worship-albums', C\WorshipAlbumController::class);
Route::resource('worship-artists', C\WorshipArtistController::class);
Route::resource('demos', C\DemoController::class);
Route::resource('config-categories', C\ConfigCategoryController::class);
});}); 
